use dataset, clear

net install grc1leg, replace from("http://www.stata.com/users/vwiggins/")

* Alt measure
gen inft = .
replace inft = ft_dem if pid3 == "Democrat"
replace inft = ft_rep if pid3 == "Republican"
gen outft = .
replace outft = ft_rep if pid3 == "Democrat"
replace outft = ft_dem if pid3 == "Republican"
gen ft_dist2 = inft - outft

* Collapse
collapse ft_dist ft_dist2, by(year)
sum year
gen time = (year-r(min))/(r(max)-r(min))
orthpoly time, generate(time1 time2) degree(2)

* Mean difference
twoway ///
(scatter ft_dist year) ///
(fpfit ft_dist year) ///
, ///
title("Mean difference") ///
xtitle("Year") ///
ytitle("Average absolute difference") ///
ylab(, angle(horiz) nogrid) ///
legend(rows(1) order(2 1) label(2 "Estimates") label(1 "Polynomial trend")) ///
scheme(s2mono) ///
graphregion(fcolor(white) lcolor(white)) ///
name(g1, replace) ///
nodraw

* Mean difference (alt)
twoway ///
(scatter ft_dist2 year) ///
(fpfit ft_dist2 year) ///
, ///
title("In-party minus out-party difference") ///
xtitle("Year") ///
ytitle("Average difference") ///
ylab(, angle(horiz) nogrid) ///
legend(rows(1) order(2 1) label(2 "Estimates") label(1 "Polynomial trend")) ///
scheme(s2mono) ///
graphregion(fcolor(white) lcolor(white)) ///
name(g2, replace) ///
nodraw


* Combine
grc1leg g1 g2, ///
rows(1) ///
scheme(s2mono) ///
graphregion(fcolor(white)) ///
name(g12, replace)

graph display g12, xsize(6) ysize(4)

gr export "figureA12.eps", replace
